<?php

/**
 * @author @author Samrat Khan & Sadik Sarfaraz - Apr 8, 2013
 */
    require('top.inc.php');
    $formLoad = new Form();
?>
<?php
if(isset($_SESSION['user']) && $_SESSION['user']['utype'] == 1 || $_SESSION['user']['utype'] == 2) {
    $sess_cusID = $_SESSION['user']['cus_id'];
    
    if(isset($_POST['addProject'])) {
        $query = "INSERT INTO projects ( projectname, cus_id, inserteddate ) VALUES ( :projectname, :cus_id, :inserteddate )";
        $query_params = array(
            ':projectname' => $_POST['projectname'],
            ':cus_id' => $_POST['cus_id'],
            ':inserteddate' => date('Y-m-d H:i:s')
        );
        
        try {
            $stmt = $db->prepare($query);
            $result = $stmt->execute($query_params);
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }
        if($result) {
            echo $msg['39'];
        }
    } else {
?>
<form class="form-horizontal" action="" method="post" id="addProject">
    <div class="control-group">
        <label class="control-label" for="projectname"><?php echo $projects['projectname']; ?></label>
        <div class="controls">
            <?php echo $formLoad->textField('projectname', "span2", "", $projects['projectname']); ?>
        </div>
    </div>
    
    <div class="control-group">
        <label class="control-label" for="cusname"><?php echo $customer_info['cusname']; ?></label>
        <div class="controls">
            <?php
                $nameCustomer = getCustomer($sess_cusID, $db);
                echo $formLoad->textFieldReadyOnly("", "span2", "", "readonly", $nameCustomer, $nameCustomer);
                echo $formLoad->hiddenField("cus_id", "span2", "", $nameCustomer, $sess_cusID);
                //echo $formLoad->textField('cus_id', "span2", "", $nameCustomer, $sess_cusID);
            ?>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="inputProject">&nbsp;</label>
        <div class="controls"><input class="btn btn-primary" type="submit" value="Add Project" name="addProject" /></div>
    </div>
</form>
<?php
    }
} else {
    header("Location: login.php");
}
?>
<?php
    include ('bottom.inc.php');
?>